@MK it's important to understand that wifisetup simply uses UCI to modify the WiFi setup and then bring the interface up, it has no functionality to check the WiFi subsequently is connected, only that it is enabled. If you bring the WiFi interface up (wifisetup does this) if the SID/encryption/passphrase are rejected by the router the interface goes down then up, then down. A little like playing on a pogo stick. The solution I use in my own app is to wait 15 seconds after the interface comes up then ping a known good ip. 8.8.8.8 and 8.8.4.4 a good bets as they're Google's DNS servers. I don't do this in scripts, I wrote it into my app, but you can also use a script accessible via UBUS directly or using mod-ubus (see docs)